const { createApp } = Vue;

createApp({
    data() {
        return {
            availableDates: [],
            selectedDate: '',
            timeSlots: [
                '09:00-10:00',
                '10:00-11:00',
                '11:00-12:00',
                '14:00-15:00',
                '15:00-16:00',
                '16:00-17:00'
            ],
            selectedTime: '',
            faqs: [
                {
                    id: 1,
                    question: '如何选择合适的咨询师？',
                    answer: '您可以查看咨询师的专业背景、擅长领域等信息，选择最适合您的咨询师。',
                    isOpen: false
                }
            ]
        };
    },
    created() {
        // 生成今天和未来6天的日期
        const today = new Date();
        const dates = [];

        // 生成7天的日期
        for (let i = 0; i < 7; i++) {
            const date = new Date(today);
            date.setDate(today.getDate() + i);
            dates.push({
                value: this.formatDate(date),
                label: this.formatDateLabel(date),
                dayOfWeek: date.getDay()
            });
        }

        // 过滤掉周末
        this.availableDates = dates.filter(date => {
            return date.dayOfWeek !== 0 && date.dayOfWeek !== 6;
        });

        // 如果过滤后日期不足，继续往后找工作日
        while (this.availableDates.length < 5) {
            const lastDate = new Date(today);
            lastDate.setDate(today.getDate() + dates.length);
            if (lastDate.getDay() !== 0 && lastDate.getDay() !== 6) {
                this.availableDates.push({
                    value: this.formatDate(lastDate),
                    label: this.formatDateLabel(lastDate),
                    dayOfWeek: lastDate.getDay()
                });
            }
            dates.length++;
        }
    },
    methods: {
        formatDate(date) {
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0');
            const day = String(date.getDate()).padStart(2, '0');
            return `${year}-${month}-${day}`;
        },
        formatDateLabel(date) {
            const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
            const today = new Date();
            today.setHours(0, 0, 0, 0);
            const isToday = date.getTime() === today.getTime();
            const weekday = weekdays[date.getDay()];
            return `${this.formatDate(date)} ${weekday}${isToday ? ' (今天)' : ''}`;
        },
        handleSubmit() {
            if (!this.selectedDate || !this.selectedTime) {
                alert('请选择预约日期和时间');
                return;
            }
            // 这里处理预约提交逻辑
            console.log('预约信息：', {
                date: this.selectedDate,
                time: this.selectedTime
            });
            alert('预约成功！');
        },
        toggleFaq(faq) {
            faq.isOpen = !faq.isOpen;
        }
    }
}).mount('#app'); 